package edu.turtlekit2.warbot.exec;

import java.util.List;

import madkit.kernel.MessageException;

import edu.turtlekit2.warbot.WarBrain;
import edu.turtlekit2.warbot.WarExec;
import edu.turtlekit2.warbot.agents.WarBase;
import edu.turtlekit2.warbot.message.Message;
import edu.turtlekit2.warbot.message.WarMessage;
import edu.turtlekit2.warbot.percepts.Percept;
import edu.turtlekit2.warbot.team1.BrainBase1;
import edu.turtlekit2.warbot.team2.BrainBase2;

public class WarBaseExec extends WarExec {
	
	private WarBrain								_mineBrain = null;
	private WarBase									_mineBase = null;

	public WarBaseExec(WarBase wb){
		_mineBase = wb;
		if(_mineBase.getTeam().equals("1")) {
			_mineBrain = new BrainBase1(this);
		}else{
			_mineBrain = new BrainBase2(this);
		}
	}
	
	public void broadcastMessage(String unite, String message, String[] content){
		WarMessage m = new WarMessage(_mineBase.xcor(), _mineBase.ycor(), _mineBase.mySelf(), _mineBase.getTeam(), _mineBase.getType(), message, content);
		if(unite != null){
			System.out.println(unite);
			_mineBase.broadcastMessage(_mineBase.getMyGroups()[0], unite, m);
		}else{
			List<String> list = _mineBase.getListRole();
			
			for(int i = 0 ; i < list.size() ; ++i){
				_mineBase.broadcastMessage(_mineBase.getMyGroups()[0], list.get(i), m);
			}
		}
	}
	
	@Override
	public String action() {
		// TODO Auto-generated method stub
		return _mineBrain.action();
	}

	@Override
	public List<Percept> getPercepts() {
		return _mineBase.getPercept();
	}
}
